#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;
using PII = pair<int, int>;
const int N = 1e4 + 10, M = 2 * N;

int n, m;
int h[N], e[M], ne[M], w[M], idx;
int p[N];
int res[M];
int st[N];
int dist[N];
vector<PII> query[M];

void add(int a, int b, int c){
    e[idx] = b;
    ne[idx] = h[a];
    w[idx] = c;
    h[a] = idx ++;
}

void dfs(int u, int fa){
    for(int i = h[u]; ~i; i = ne[i]){
        int j = e[i];
        if(j == fa) continue;

        dist[j] = dist[u] + w[i];
        dfs(j, u);
    }
}

int find(int x){
    if(x != p[x]){
        p[x] = find(p[x]);
    }

    return p[x];
}

void tarjan(int u){
    st[u] = 1;
    for(int i = h[u]; ~i; i = ne[i]){
        int j = e[i];
        if(!st[j]){
            tarjan(j);
            p[j] = u;
        }
    }

    for(auto& temp : query[u]){
        int ver = temp.first, id = temp.second;
        if(st[ver] == 2){
            int ca = find(ver);
            res[id] = dist[u] + dist[ver] - dist[ca] * 2;
        }
    }

    st[u] = 2;

}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    memset(h, -1, sizeof h);

    scanf("%d%d", &n, &m);
    for(int i = 0; i < n - 1; i ++){
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        add(a, b, c), add(b, a, c);
    }

    for(int i = 0; i < m; i ++){
        int a, b;
        scanf("%d%d", &a, &b);
        if(a != b){
            query[a].push_back({b, i});
            query[b].push_back({a, i});
        }
    }

    for(int i = 1; i <= n; i ++) p[i] = i;

    dfs(1, -1);
    tarjan(1);

    for(int i = 0; i < m; i ++){
        printf("%d\n", res[i]);
    }

    return 0;
    
}